package LeXin;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Description：
 * Author: zhangc
 * Date：2017/9/23 20:11
 */
public class Last {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int time = sc.nextInt();
        int total = sc.nextInt();
        String s = sc.nextLine();
        List<Integer> list = new ArrayList<>();
        String[] split = s.trim().split(" ");
        for (int i = 0; i < split.length; i++) {
            list.add(Integer.parseInt(split[ i ]));
        }
        List<Integer> list1 = new ArrayList<>();
        String s1 = sc.nextLine();
        String[] split1 = s1.trim().split(" ");
        for (int i = 0; i < split1.length; i++) {
            list1.add(Integer.parseInt(split1[ i ]));
        }
        int[] a = new int[ list.size() ];
        for (int i = 0; i < list.size(); i++) {
            a[ i ] = list.get(i);
        }
        int[] b = new int[ list1.size() ];
        for (int i = 0; i < list1.size(); i++) {
            b[ i ] = list1.get(i);
        }
        System.out.println(getMax(a, b, total, time));
    }

    private static int getMax(int[] x, int[] y, int total, int time) {
        boolean[] status = new boolean[ x.length ];
        for (int i = 0; i < status.length; i++) {
            status[ i ] = false;
        }
        int result = 0;

        for (int z = 0; z < time; z++) {
            int max = 0;
            int st = -1;
            for (int i = 0; i < y.length; i++) {
                if (y[ i ] <= total && !status[ i ] && x[ i ] > max) {
                    max = x[ i ];
                    st = i;
                }
            }
            if (st != -1) {
                status[ st ] = true;
                result += max;
                total += x[ st ];
            }
        }
        return result;
    }

//    @Test
//    public void test() {
//        int[] a = {1, 2, 3};
//        int[] b = {0, 1, 1};
//        System.out.println(getMax(a, b, 0, 2));
//    }
}